<?
layout("/inc/layout.html",{title:sysTitle}){
?>

<div id="page-wrapper">
	<!--BEGIN TITLE & BREADCRUMB PAGE-->
	<div id="title-breadcrumb-option-demo" class="page-title-breadcrumb">
		<div class="page-header pull-left">
			<div class="page-title">日志管理</div>
		</div>
		<div class="clearfix"></div>
	</div>
	<!--END TITLE & BREADCRUMB PAGE-->
	<!--BEGIN CONTENT-->
	<div class="page-content">


		<div class="row mbl" >
			<div class="col-lg-10">
				<table style="width: 100%;">
					<tr height="50">
						<td align="right" style="width: 100px;">IP地址:&nbsp;&nbsp;</td>
						<td><input type="text"  class="form-control" id="createIpAddress" name="createIpAddress" /></td>
						<td align="right" style="width: 100px;">用户类型:&nbsp;&nbsp;</td>
						<td style="width: 45%;">
							<select class="form-control" id="operatorType">
									<option value="">全部</option>
									<option value="0">其他</option>
									<option value="1">后台用户</option>
									<option value="2">APP用户</option>
								</select>
						</td>
					</tr>
					<tr height="50">
						<td align="right" style="width: 100px;">操作类型:&nbsp;&nbsp;</td>
						<td>
							<select class="form-control" id="businessType">
								<option value="">全部</option>
								<option value="0">其它</option>
								<option value="1">新增</option>
								<option value="2">修改</option>
								<option value="3">删除</option>
								<option value="4">审核</option>
								<option value="5">发布</option>
								<option value="6">启用</option>
								<option value="7">禁用</option>
							</select>
						</td>
						<td align="right" style="width: 100px;">用户名:&nbsp;&nbsp;</td>
						<td><input type="text"  class="form-control" id="createUser" name="createUser" /></td>
						
					</tr>
					<tr>
						<td align="right" style="width: 100px;">电话:&nbsp;&nbsp;</td>
						<td><input type="text"  class="form-control" id="telephone" name="telephone" /></td>
						<td align="right" style="width: 100px;"><button type="button" data-toggle="dropdown" class="btn btn-blue dropdown-toggle" onclick="get()">查询</button></td>
						<td align="left" style="width: 100px;"><button style="margin-left: 5px;" type="button" data-toggle="dropdown" class="btn btn-blue dropdown-toggle" onclick="toExcel()">导出Excel</button></td>
					</tr>
				</table>
				<button class="btn btn-sm btn-blue" onclick="del('0')">批量删除 </button>&nbsp;&nbsp;
				<button class="btn btn-sm btn-blue" onclick="clearAllLog()">清空 </button>&nbsp;&nbsp;
			</div>
		</div>

		<table
			class="table table-hover table-striped table-bordered table-advanced tablesorter mbn">
			<thead>
				<tr>
					<th> <input type="checkbox" onclick="selectAll(this)" class="checkall" name="oncheckall" /></th>
					<th>序号</th>
					<th>用户类型</th>
					<th>操作类型</th>
					<th>日志内容</th>
					<th>IP地址</th>
					<th>访问用户</th>
					<th>电话</th>
					<th>URI</th>
					<th width="300px">请求参数</th>
					<th width="300px">异常信息</th>
					<th>操作时间</th>
				</tr>
			</thead>
			<tbody id="findUser">
				<!-- <tr>
					<td><input name="checkall" type="checkbox"/></td>
					<td>505281</td>
					<td>admin</td>
					<td>127.0.0.1</td>
					<td>北京</td>
					<td>Chrome</td>
					<td>windows</td>
					<td>成功</td>
					<td>登录成功</td>
					<td>2019-11-12 12:12:00</td>
				</tr>
				-->
				
				
			</tbody>
		</table>
		<div id="page2" style="text-align: center; margin-top: 20px;"></div>
	</div>

	<!--END CONTENT-->
</div>


<?} ?>
<script>
	var curr;
	var id;
	$(function() {
		demo1(1);
	});
	function get() {
		demo1(curr);
	}
	function getlay() {
		return id;
	}
	
	function del(id) {
		if (confirm("是否确认删除！！"))
		{
			if(id=='0'){
				id='';
				$("#findUser").find("input[name='checkall']").each(function(){
					if($(this).prop("checked")){
						id+=$(this).val()+';'
					}
					
				});
			}
			if(id!='' && id!='0'){
				$.ajax({
					type : "post",
					url : "./logDel.do",
					data : {
						"ids" : id
					},
					dataType : "json",
					success : function(data) {
						if(data[0].result=='success'){
							demo1(curr);
						}
						layer.msg(data[0].msg);
					},
					error : function(data) {
						alert("请求失败");
					}
				});
			}else{
				layer.msg("请选择数据")
			}
		}
	}
	function delAll() {
		if (confirm("是否确认清空！！"))
		{
			
			$.ajax({
				type : "post",
				url : "./logDelAll.do",
				dataType : "json",
				success : function(data) {
					if(data[0].result=='success'){
						demo1(curr);
					}
					layer.msg(data[0].msg);
				},
				error : function(data) {
					alert("请求失败");
				}
			});
		}
	}
	function demo1(cur) {
		$.getJSON("./logList.do",
			{
				page : cur || 1,
				createIpAddress:$("#createIpAddress").val(),
				businessType:$("#businessType").val(),
        		operatorType:$("#operatorType").val(),
        		createUser:$("#createUser").val(),
        		telephone:$("#telephone").val(),
			},
			function(res) {
				//此处仅仅是为了演示变化的内容
				var str = "";
				$("#findUser").html("");
				if(res.listsize>0){
					$("#dataNull").html("");
				}else{
					$("#dataNull").html("<span class='subtitle' style='font-size: 15px;'>数据为空!</span>");
				}
				for ( var i = 0; i < res.listsize; i++) {
					str += "<tr><td>"
							+ '<input name="checkall" type="checkbox" value="'+res.result[i].id+'"/>'
							+ '</td><td>'
							+ (i + 1)
							+ "</td><td> <label id=>";
							if(res.result[i].operatorType=='0'){
								str += '其他';
							}else if(res.result[i].operatorType=='1'){
								str += '后台用户';
							}else if(res.result[i].operatorType=='2'){
								str += 'APP用户';
							}
							str+= "</label></td><td><label >";
							if(res.result[i].businessType=='0'){
								str += '其它';
							}else if(res.result[i].businessType=='1'){
								str += '新增';
							}else if(res.result[i].businessType=='2'){
								str += '修改';
							}else if(res.result[i].businessType=='3'){
								str += '删除';
							}else if(res.result[i].businessType=='4'){
								str += '审核';
							}else if(res.result[i].businessType=='5'){
								str += '发布';
							}else if(res.result[i].businessType=='6'){
								str += '启用';
							}else if(res.result[i].businessType=='7'){
								str += '启用';
							}
							str+= "</label></td><td><label >"
							+ res.result[i].text
							+ "</label></td><td><label >"
							+ res.result[i].createIpAddress
							+ "</label></td><td><label >"
							+ res.result[i].createUser
							+ "</label></td><td><label >"
							+ res.result[i].telephone
							+ "</label></td><td><label >"
							+ res.result[i].uri
							+ "</label></td><td width=\"300px\" title=\""+res.result[i].params+"\" onclick=\"showAll('"+res.result[i].params+"')\"><label >"
							+ subStr(res.result[i].params)
							+ "</label></td><td width=\"300px\" title=\""+res.result[i].exception+"\" onclick=\"showAll('"+res.result[i].exception+"')\"><label >"
							+ subStr(res.result[i].exception)
							+ "</label></td><td><label >"
							+ res.result[i].createTime
							+ "</label></td>"
							+ "</tr>";
				}
				$("#findUser").append(str);

				laypage({
					cont : document.getElementById('page2'), //容器。值支持id名、原生dom对象，jquery对象,
					pages : res.pageSize, //总页数
					skip : true, //是否开启跳页
					skin : 'molv', //加载内置皮肤，也可以直接赋值16进制颜色值，如:#c00
					curr: cur || 1,
					last: res.pageSize,
					groups : 6,//连续显示分页数
					jump : function(obj, first) { //触发分页后的回调
						if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
							demo1(obj.curr);
			                 curr=obj.curr;
						}
					}
				});
			});
	};

function toExcel(){
	if (confirm("是否确认导出！！")){
		var index = layer.msg('正在生产excel...', {icon: 16,shade: [0.5, '#f5f5f5'],scrollbar: false,time: 0});
		$.ajax({
			type : "post",
			url : "./toExcel.do",
			dataType : "text",
			data:{
				createIpAddress:$("#createIpAddress").val(),
				businessType:$("#businessType").val(),
		   		operatorType:$("#operatorType").val(),
		   		createUser:$("#createUser").val(),
		   		telephone:$("#telephone").val(),
			},
			success : function(data) {
				layer.close(index);
				if(data!=''){
					window.location.href="./logDownLoad.do?path="+encodeURI(data);
				}
			},
			error : function(data) {
				layer.close(index);
				alert("请求失败");
			}
		});
	}
	
}


	function subStr(text){
		if(text.length>30){
			text=text.substr(0, 30)+" ...";
		}
		return text;
	}
	function showAll(text){
		if(text!=''){
			layer.alert(text);
		}
	}
	
	function clearAllLog(){
		if (confirm("是否确认清空日志！！")){
		var index = layer.msg('正在清空...', {icon: 16,shade: [0.5, '#f5f5f5'],scrollbar: false,time: 0});
		$.ajax({
			type : "post",
			url : "./logDelAll.do",
			dataType : "json",
			success : function(data) {
				layer.close(index);
				if(data[0].result=='success'){
					get()
				}
				layer.msg(data[0].msg);
			},
			error : function(data) {
				layer.close(index);
				alert("请求失败");
			}
		});
	}
	}
</script>